<template>
    <view class="flex-between nav-box" ref="nav">
        <view
            class="nav-type"
            v-for="(item, index) in list"
            :key="index"
            :class="{ active: modelValue === index + 1 }"
            @click="
                change({
                    ...item,
                    index: index + 1
                })
            "
        >
            {{ item.text }}
        </view>
        <!-- <view
      class="nav-type"
      :class="{ active: page.params.bizTarget === '2' }"
      @click="bizTargetSwitch(2)"
    >
      推荐
    </view> -->
        <view
            class="dot"
            :style="{
                transform: `translateX(${modelValue === 1 ? 0 : disp || '240rpx'})`
            }"
        ></view>
    </view>
</template>

<script lang="ts" setup>
const props = defineProps(['list', 'modelValue', 'disp'])
const emit = defineEmits(['change', 'update:modelValue'])

const change = (row: any) => {
    emit('change', row)
    emit('update:modelValue', row.index)
}
</script>

<style scoped lang="scss">
.nav-box {
    //width: 100%;
    width: 300rpx;
    //padding: 0 80rpx;
    font-size: 15px;
    margin: auto;
    color: #7b7b7b;
    position: relative;
    .dot {
        content: '';
        display: block;
        width: 60rpx;
        height: 10rpx;
        background-color: #3c8bfb;
        position: absolute;
        bottom: -10rpx;
        left: 0;
        border-radius: 999rpx;
        transition: all 0.3s;
    }
    .active {
        color: #1a1a1a;
        font-size: 16px;
        font-weight: 700;
    }
}
</style>
